package bg.btanev.eightyfour.service.pooling.que;

import java.util.Date;

import org.apache.commons.lang.Validate;

public final class QueItem implements Comparable<QueItem> {
	private final Long id;
	private final Date updateDate;

	public QueItem(final Long id, final Date updateDate) {
		super();

		Validate.notNull(id);
		Validate.notNull(updateDate);

		this.id = id;
		this.updateDate = updateDate;
	}

	public Long getId() {
		return id;
	}

	public Date getUpdateDate() {
		return updateDate;
	}

	@Override
	public int compareTo(QueItem o) {
		return this.updateDate.compareTo(o.updateDate);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((updateDate == null) ? 0 : updateDate.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		QueItem other = (QueItem) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (updateDate == null) {
			if (other.updateDate != null)
				return false;
		} else if (!updateDate.equals(other.updateDate))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "QueItem [id=" + id + ", updateDate=" + updateDate + "]";
	}
}
